(function() {
	var page = pf.newPage('movie');
	var $el = null;
	var MovieScroll;
	// var move_date = ["pcca_preview", "snowforce", "driving_school_preview", "DNA", "driving_school","pcca"];
	/**
	 * 初始化时调用
	 */
	page.onCreate = function() {
		$el = page.$el;
		video_url_change = {
			CAYENNE: "./video/movie/CAYENNE.mp4",
			LiChao: "./video/movie/LiChao.mp4",
			YangWu: "./video/movie/YangWu.mp4",
			ZhangLei: "./video/movie/ZhangLei.mp4",
			ZhouKaiyuan: "./video/movie/ZhouKaiyuan.mp4",
			// DNA: "./video/movie/DNA.mp4",
			Turbo: "./video/movie/Turbo.mp4",
		}
		$el.on('click', '.video_image_play', function() {
			var url_new = $(this).attr("video_url");
			window.clearTimeout(video_set);
				var video_set=window.setTimeout(function() {
					pf.overlay('play_video');
			},200);
			// kpi
			kpi.store('videos', url_new);
			
			pcc2.playVideo(video_url_change[url_new]);
		});
			MovieScroll = new iScroll("scroller_movie",{
			momentum:    false,
			snap:true,
			vScroll:    false,
			vScrollbar: false,
			hScrollbar: false,
			click:      true
		});
		function tf(es){
			var r= /^[+-]?[1-9]?[0-9]*\.[0-9]*$/;
	    return r.test(es);
		}
		$el.on('click','.movie_left',function(){
			pcc2.css3(".movie_float.hi-icon.hi-icon-mobile.movie_left");
			$el.find(".movie_float").css("opacity","1");
			if(MovieScroll.currPageX == 0){
				$el.find($(this)).css("opacity","0");
			}
			if(MovieScroll.currPageX == 1){
				$el.find($(this)).css("opacity","0");	
			}
			if(MovieScroll.currPageX == 0){
				// MovieScroll.scrollToPage(1, 0, 0);
			}else{
				MovieScroll.scrollToPage(MovieScroll.currPageX-1, 0, 500);
			}
		});
		$el.on('click','.movie_right',function(){
			pcc2.css3(".movie_float.hi-icon.hi-icon-mobile.movie_right");
			$el.find(".movie_float").css("opacity","1");
			if(MovieScroll.currPageX+2 > 1){
				$el.find($(this)).css("opacity","0");	
			}
			if(MovieScroll.currPageX == 1){
				// MovieScroll.scrollToPage(0, 0, 0);
			}else{
				MovieScroll.scrollToPage(MovieScroll.currPageX+1, 0, 500);
			}
		});
	};

	/**
	 * 页面显示时自动调用
	 */
	page.onShow = function() {
		var videoC = {
			CAYENNE:     {name:__("new_cayenne"), time:'04:29'},
			LiChao:      {name:__("lichao"), time:'02:04'},
			YangWu:      {name:__("yangwu"), time:'02:09'},
			ZhangLei:    {name:__("zhanglei"), time:'01:58'},
			ZhouKaiyuan: {name:__("zhou"), time:'02:08'},
			Turbo:       {name:__("walter_vid"), time:'02:50'}
			// DNA:         {name:"DNA", time:'02:58'},
		};

		
		// $el.show();
		MovieScroll.refresh();
		var second = 0;
		for (var i in video_url_change) {
			$('.video_number').eq(second).append('<div video_url=' + i + ' class="video_image_play"><div class="video_play sprite icon-btn"></div><video class="vide_id" loop="loop" style="  width: 100%;height: 100%;" autoplay="autoplay"><source src=' + (video_url_change[i].replace(".mp4", "_preview.mp4")) + ' type="video/mp4"></video></div><div class="video_name">'+videoC[i]['name']+'</div><div class="video_length">'+videoC[i]['time']+'</div>');
			second = second + 1;
		};
	};

	/**
	 * 页面隐藏时调用
	 */
	page.onHide = function() {
		$el.find('.video_number').empty();
		// $el.hide();
	};

})();